<?php

namespace app\admin\controller;

use app\Request;
use app\admin\service\Account as AccountService;
use app\admin\validate\Account as ValidateAccount;
use app\model\ProductCategory;
use think\facade\Cache;
use think\facade\View;

class Account
{
    public function index()
    {
        $data = [
            'username' => '111'
        ];
        try {
            validate(ValidateAccount::class)->scene('index')->check($data);
        } catch (\think\exception\ValidateException $th) {

            return fail($th->getError());
        }
    }
    public function login(Request $request)
    {
        $params = $request->params;

        //return success($params['username']);
        $token = (new AccountService())->getToken($params);
        //dump($params);
        //cache('token',null);
        $catchvalue = Cache::get($token);
        return success('操作成功', ['token' => $token]);
    }
    public function info(Request $request)
    {
        $uid = $request->uid;
        return success('操作成功', ['uid' => $uid]);
    }
    public function test()
    {
        $list = (new ProductCategory())->getPageData(1, 2);
        // 获取分页显示
        $page = $list->render();
        View::assign(['list' => $list, 'page' => $page]);
        return View::fetch('test');
    }
}
